package com.nimble.smile.service;

public class ResponseEntityBody<T> {
    private Integer operationCode = OperationCode.FAIL.getValue();

    private T body;

    private String message = OperationCode.FAIL.getReason();

    public ResponseEntityBody() {
    }

    public ResponseEntityBody(T body) {
        this.body = body;
    }

    public ResponseEntityBody(OperationCode operationCode) {
        setOperationCode(operationCode);
        setMessage(operationCode.getReason());
    }

    public ResponseEntityBody(OperationCode operationCode, T body) {
        this.operationCode = operationCode.getValue();
        this.body = body;
    }

    public ResponseEntityBody(OperationCode operationCode, T body, String message) {
        this.operationCode = operationCode.getValue();
        this.body = body;
        this.message = message;
    }

    public static <T> ResponseEntityBody<T> success(T body) {
        return new ResponseEntityBody<T>(OperationCode.SUCCESS, body);
    }

    public static ResponseEntityBody success() {
        return new ResponseEntityBody(OperationCode.SUCCESS);
    }

    public static <T> ResponseEntityBody<T> fail(T body) {
        return new ResponseEntityBody<T>(OperationCode.FAIL, body);
    }

    public static ResponseEntityBody fail() {
        return new ResponseEntityBody();
    }

    public static <T> ResponseEntityBody<T> otherError(OperationCode operationCode) {
        return new ResponseEntityBody(operationCode.getValue());
    }

    public static <T> ResponseEntityBody<T> otherError(OperationCode operationCode, T body) {
        return new ResponseEntityBody(operationCode, body);
    }

    public Integer getOperationCode() {
        return operationCode;
    }

    public void setOperationCode(OperationCode operationCode) {
        this.operationCode = operationCode.getValue();
        this.message = operationCode.getReason();
    }

    public T getBody() {
        return body;
    }

    public void setBody(T body) {
        this.body = body;
    }


    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
